﻿/******************************************************************************
 * Copyright (C) 2015  671643387@qq.com
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the
 * Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 *****************************************************************************/

#ifndef REALMD_AUTHCODE_H_
#define REALMD_AUTHCODE_H_

#if defined(_MSC_VER) && (_MSC_VER >= 1200)
# pragma once
#endif

#include <cstdint>
#include <cstddef>


/* 登录验证命令 */
enum eAuthCmd
{
    CMD_AUTH_LOGON_CHALLENGE		= 0x00,
    CMD_AUTH_LOGON_PROOF			= 0x01,
    CMD_AUTH_RECONNECT_CHALLENGE	= 0x02,
    CMD_AUTH_RECONNECT_PROOF		= 0x03,
    CMD_REALM_LIST					= 0x10,
    AUTH_TOTAL_COMMANDS
};

/* 登录验证结果 */
enum eAuthResult
{
    WOW_SUCCESS						= 0x00,
    WOW_FAIL_UNKNOWN0				= 0x01,
    WOW_FAIL_UNKNOWN1				= 0x02,
    WOW_FAIL_BANNED					= 0x03,
    WOW_FAIL_UNKNOWN_ACCOUNT		= 0x04,
    WOW_FAIL_INCORRECT_PASSWORD		= 0x05,

    WOW_FAIL_ALREAY_ONLINE			= 0x06,
    WOW_FAIL_NO_TIME				= 0x07,
    WOW_FAIL_DB_BUSY				= 0x08,
    WOW_FAIL_VERSION_INVALID		= 0x09,
    WOW_FAIL_VERSION_UPDATE			= 0x0A,
    WOW_FAIL_INVALID_SERVER			= 0x0B,
    WOW_FAIL_SUSPENDED				= 0x0C,
    WOW_FAIL_FAIL_NOACCESS			= 0x0D,
    WOW_SUCCESS_SURVEY				= 0x0E,
    WOW_FAIL_PARENTCONTROL			= 0x0F,
    WOW_FAIL_LOCKED_ENFORCED		= 0x10,
    WOW_FAIL_TRIAL_ENDED			= 0x11,
    WOW_FAIL_USE_BATTLENET			= 0x12
};


#if defined( __GNUC__ )
#pragma pack(1)
#else
#pragma pack(push,1)
#endif

/* 客户端请求登录发送的第一个包 */
typedef struct AUTH_LOGON_CHALLENGE_C
{
    std::uint8_t     cmd;
    std::uint8_t     error;
    std::uint16_t    size;
    std::uint8_t     gamename[4];
    std::uint8_t     version1;
    std::uint8_t     version2;
    std::uint8_t     version3;
    std::uint16_t    build;
    std::uint8_t     platform[4];
    std::uint8_t     os[4];
    std::uint8_t     country[4];
    std::uint32_t    timezone_bias;
    std::uint32_t    ip;
    std::uint8_t     I_len;
    std::uint8_t     I[1];
}sAuthLogonChallenge_C;

/* 客户端请求登录发送的验证数据包 */
typedef struct AUTH_LOGON_PROOF_C
{
    std::uint8_t     cmd;
    std::uint8_t     A[32];
    std::uint8_t     M1[20];
    std::uint8_t     crc_hash[20];
    std::uint8_t     number_of_keys;
    std::uint8_t     securityFlags;
} sAuthLogonProof_C;

/* 服务器确认登录验证成功后发送给客户端的确认数据 */
typedef struct AUTH_LOGON_PROOF_S_BUILD_6005
{
    std::uint8_t     cmd;
    std::uint8_t     error;
    std::uint8_t     M2[20];
    // std::uint32  unk1;
    std::uint32_t     unk2;
    // std::uint16  unk3;
} sAuthLogonProof_S_BUILD_6005;

typedef struct AUTH_RECONNECT_PROOF_C
{
    std::uint8_t     cmd;
    std::uint8_t     R1[16];
    std::uint8_t     R2[20];
    std::uint8_t     R3[20];
    std::uint8_t     number_of_keys;
} sAuthReconnectProof_C;

#if defined( __GNUC__ )
#pragma pack()
#else
#pragma pack(pop)
#endif

#endif // REALMD_AUTHCODE_H_
